<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="" prop="brand">
        <!-- <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.brand"
          placeholder="选择品牌"
          clearable
          filterable
        >
          <el-option
            v-for="dict in BrandList"
            :key="dict"
            :label="dict"
            :value="dict"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="channel">
        <!-- <el-input
          v-model="queryParams.channel"
          placeholder="请输入渠道"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.channel"
          placeholder="选择渠道"
          clearable
          filterable
        >
          <el-option
            v-for="dict in ChannelList"
            :key="dict"
            :label="dict"
            :value="dict"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="shopName">
        <!-- <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.shopName"
          placeholder="选择店铺"
          clearable
          filterable
        >
          <el-option
            v-for="dict in ShopList"
            :key="dict"
            :label="dict"
            :value="dict"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="店铺id" prop="shopId">
        <el-input
          v-model="queryParams.shopId"
          placeholder="请输入店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="" prop="commentTime">
        <el-date-picker
          clearable
          v-model="queryParams.commentTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择评价时间"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="" prop="commentContent">
        <el-input
          v-model="queryParams.commentContent"
          placeholder="请输入评价内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="commentType">
        <el-select
          v-model="queryParams.commentType"
          placeholder="评价类型"
          clearable
        >
          <el-option
            v-for="(dict, i) in typeArr"
            :key="i"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- 
      <el-form-item label="月" prop="dataMonth">
        <el-input
          v-model="queryParams.dataMonth"
          placeholder="请输入月"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周" prop="dataWeek">
        <el-input
          v-model="queryParams.dataWeek"
          placeholder="请输入周"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="" prop="auditResult">
        <!-- <el-input
          v-model="queryParams.auditResult"
          placeholder="是否匹配"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.auditResult"
          placeholder="智能复核结果"
          clearable
        >
          <el-option label="匹配" value="匹配" />
          <el-option label="不匹配" value="不匹配" />
          <el-option label="空白" value="空白" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
      <br />
      <el-form-item label="评价时间:" label-width="80px">
        <timeSearch
          @getDateArr="getDateArr"
          @changDay="changDay"
          :timeArr="timeArr"
          :dayActive="this.dayActive"
          :dayLimit="1095"
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['comment:BiCommentFirstDwd:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['comment:BiCommentFirstDwd:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['comment:BiCommentFirstDwd:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['comment:BiCommentFirstDwd:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="handlegetCommentTypeByFirstId"
          >打标</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button size="mini" @click="openType = true">按时间打标</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleauditResultThreeCommentS"
          >智能复核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="openauditResult = true"
          >按时间智能复核</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          v-show="this.roles.includes('admin')"
          type="primary"
          size="mini"
          @click="handleGo('/comment/FirstDwd')"
          >无标签数据</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          @click="opendelete = true"
          v-hasPermi="['comment:BiCommentFirstDwd:deleteImproperByDate']"
          >按时间删除不匹配</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="openoneClick = true"
          >一键打标</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-dialog
      :visible.sync="openType"
      width="700px"
      append-to-body
      v-if="openType"
      title="请选择时间段"
    >
      <commonDay
        @getDateArr="getcommonDay"
        @changDay="changcommonDay"
        :timeArr="timeArrList"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleRefreshCache"
          >按时间打标</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openoneClick"
      width="700px"
      append-to-body
      v-if="openoneClick"
      title="请选择时间段"
    >
      <commonDay
        @getDateArr="getcommonDay"
        @changDay="changcommonDay"
        :timeArr="timeArrList"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleoneClick">一键打标</el-button>
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openauditResult"
      width="700px"
      append-to-body
      v-if="openauditResult"
      title="请选择时间段"
    >
      <commonDay
        @getDateArr="getcommonDay"
        @changDay="changcommonDay"
        :timeArr="timeArrList"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleauditResultThreecommentsByDate"
          >按时间智能复核</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="opendelete"
      width="700px"
      append-to-body
      v-if="opendelete"
      title="请选择时间段"
    >
      <commonDay
        @getDateArr="getcommonDay"
        @changDay="changcommonDay"
        :timeArr="timeArrList"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handledeleteImproperByDate"
          >按时间删除不匹配</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-table
      v-loading="loading"
      :data="BiCommentFirstDwdList"
      @selection-change="handleSelectionChange"
      :height="620"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="渠道" align="center" prop="channel" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <!-- <el-table-column label="店铺id" align="center" prop="shopId" /> -->
      <el-table-column label="item" align="center" prop="item" />
      <el-table-column label="评价时间" align="center" prop="commentTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.commentTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="580"
        label="评价内容"
        align="center"
        prop="commentContent"
      >
        <template slot-scope="scope">
          <mypopover :popoverInput="scope.row.commentContent" /> </template
      ></el-table-column>
      <el-table-column label="评价类型" align="center" prop="commentType">
        <template slot-scope="scope">
          <span
            slot="reference"
            style="color: #409eff; cursor: pointer"
            size="mini"
            @click="getBiCommentSecondDwdList(scope.row)"
            >{{ scope.row.commentType }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        width="180"
        label="评价归类"
        align="center"
        prop="secondLevelCategory"
      >
        <template slot-scope="scope">
          <span
            slot="reference"
            style="color: #409eff; cursor: pointer"
            size="mini"
            @click="getBiCommentSecondDwdList(scope.row)"
            >{{ scope.row.secondLevelCategory }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        width="180"
        label="评价关键词"
        align="center"
        prop="threeLevelCategory"
      >
        <template slot-scope="scope">
          <span
            slot="reference"
            style="color: #409eff; cursor: pointer"
            size="mini"
            @click="getBiCommentSecondDwdList(scope.row)"
            >{{ scope.row.threeLevelCategory }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="智能复核结果" align="center" prop="auditResult" />
      <el-table-column label="年" align="center" prop="dataYear" />
      <el-table-column label="月" align="center" prop="dataMonth" />
      <el-table-column label="周" align="center" prop="dataWeek" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['comment:BiCommentFirstDwd:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['comment:BiCommentFirstDwd:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评价类型对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="评价时间" prop="commentTime">
          <el-date-picker
            clearable
            v-model="form.commentTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择评价时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="评价内容">
          <editor v-model="form.commentContent" :min-height="192" />
        </el-form-item>
        <el-form-item label="年" prop="dataYear">
          <el-input v-model="form.dataYear" placeholder="请输入年" />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input v-model="form.dataMonth" placeholder="请输入月" />
        </el-form-item>
        <el-form-item label="周" prop="dataWeek">
          <el-input v-model="form.dataWeek" placeholder="请输入周" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <!-- 文件上传-->
      <el-form
        :rules="rules"
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        @submit.native.prevent
        ><el-form-item label="原始评价类型:" prop="commentType">
          <el-select
            v-model="dataForm.origCommentType"
            placeholder="好评/差评"
            clearable
          >
            <el-option label="好评" value="好评" />
            <el-option label="差评" value="差评" />
          </el-select>
        </el-form-item>

        <el-form-item label="文件：" prop="file">
          <el-upload
            class="upload-import"
            ref="uploadImport"
            :http-request="httpRequest"
            action=""
            :on-remove="handleRemove"
            :file-list="fileList"
            :limit="1"
            :on-change="handleChange"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload"
          >
            <!--
            accept="application/zip,.zip" 设置接收的文件类型-->
            <el-button
              v-show="!hasFile"
              slot="trigger"
              size="small"
              type="primary"
              >选取文件</el-button
            >
            <!-- <div slot="tip" class="el-upload__tip">
          只能上传zip文件，且不超过10M
        </div> -->
          </el-upload>
          <!-- 关闭自动上传-->
        </el-form-item>
        <el-form-item label="店铺：" prop="name">
          <!-- <el-input
            type="text"
            v-model.trim="dataForm.name"
            clearable
          ></el-input> -->
          <el-cascader
            class="region"
            v-model="dataForm.name"
            placeholder="选择店铺分组"
            :options="cascadeList"
            :props="{ checkStrictly: true }"
            style="width: 300px; height: 30px"
            @change="changecascadeList"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitUpload">提交</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="dialogVisible = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :visible.sync="openInfo"
      width="1500px"
      append-to-body
      v-if="openInfo"
      @close="getList"
    >
      <div class="el-dialog-div">
        <component
          :is="'BiCommentSecondDwd'"
          :commentFirstId="commentFirstId"
          :commentContent="commentContent"
          @handleColse="handleColse"
        ></component>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import timeSearch from "@/views/chart/day/day.vue";
import commonDay from "@/common/day/index.vue";

import {
  listBiCommentFirstDwd,
  getBiCommentFirstDwd,
  delBiCommentFirstDwd,
  addBiCommentFirstDwd,
  updateBiCommentFirstDwd,
  getCommentTypeByFirstId,
  getCommentTypeByDate,
  auditResultThreeCommentS,
  auditResultThreecommentsByDate,
  selectShopList,
  selectChannelList,
  selectBrandList,
  deleteImproperByDate,
  oneClickSetDataByDate,
} from "@/api/comment/BiCommentFirstDwd";
import { listBiCommentSecondDwd } from "@/api/comment/BiCommentSecondDwd";
//--------导入token
import { getToken } from "@/utils/auth";
import axios from "axios";
import { listAll, importBiKeyword } from "@/api/chart/brandChannelShop";
import BiCommentSecondDwd from "@/views/comment/BiCommentSecondDwd/index.vue";

import { getInfo } from "@/api/login.js";
export default {
  name: "BiCommentFirstDwd",
  dicts: ["sys_product_pp"],
  components: { timeSearch, BiCommentSecondDwd, commonDay },
  props: {
    row: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      openoneClick: false,
      //当前操作用户角色
      roles: [],

      openType: false,
      openauditResult: false,
      opendelete: false,
      BrandList: [],
      ChannelList: [],
      ShopList: [],
      openInfo: false,
      commentFirstId: 0,
      commentContent: "",
      BiCommentSecondDwdList: [],
      typeArr: [
        { value: "差评", label: "差评" },
        { value: "好评", label: "好评" },
        { value: "空白", label: "空白" },
      ],

      dayActive: 365,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeArrList: [
        // { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },
      cascadeList: [],
      dataForm: {
        name: [],
        file: null,
        origCommentType: null,
      },
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { max: 50, message: "最长可输入50个字符", trigger: "blur" },
          // { validator: isvalidatName, trigger: "blur" },
        ],
        file: [{ required: true, message: "请选择上传文件", trigger: "blur" }],
      },
      hasFile: false,
      fileList: [],
      dialogVisible: false,
      pjtUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评价类型表格数据
      BiCommentFirstDwdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brand: null,
        channel: null,
        shopName: null,
        shopId: null,
        commentTime: null,
        commentContent: null,
        commentType: null,
        dataYear: null,
        dataMonth: null,
        dataWeek: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  // watch: {
  //   row: {
  //     handler: function (newnew, oldold) {
  //       if (JSON.stringify(this.row) != "{}") {
  //         // console.log(JSON.stringify(this.row));
  //         // return;
  //         this.queryParams.item = this.row.item;
  //         this.queryParams.commentType = this.row.commentType;
  //         this.getList();
  //       }
  //     },
  //     deep: true,
  //     immediate: true,
  //   },
  // },
  created() {
    this.getroles();
    this.init();
    this.getList();
    this.getdataSourceList();
  },
  methods: {
    getroles() {
      // var userId = null
      getInfo().then((res) => {
        //当前操作用户角色
        this.roles = res.roles;
        console.log(JSON.stringify(this.roles));
      });
    },
    handleGo(path) {
      this.$router.push({
        path: path,
      });
    },
    init() {
      selectShopList().then((response) => {
        this.ShopList = response;
      });
      selectChannelList().then((response) => {
        this.ChannelList = response;
      });
      selectBrandList().then((response) => {
        this.BrandList = response;
      });
    },
    handledeleteImproperByDate() {
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      deleteImproperByDate(obj).then((response) => {
        this.$modal.closeLoading();

        if (response.code == 200) {
          this.$modal.msgSuccess("批量删除不匹配成功");
          this.dayActive = 365;

          this.openType = false;
          this.openauditResult = false;
          this.opendelete = false;
          this.getList();
        }
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handleoneClick() {
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      oneClickSetDataByDate(obj).then((response) => {
        this.$modal.closeLoading();

        if (response.code == 200) {
          this.$modal.msgSuccess("打标成功");
          // this.dayActive = 365;

          this.openoneClick = false;
          // this.openauditResult = false;
          this.getList();
        }
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handleauditResultThreecommentsByDate() {
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      auditResultThreecommentsByDate(obj).then((response) => {
        this.$modal.closeLoading();

        if (response.code == 200) {
          this.$modal.msgSuccess("批量智能复核成功");
          this.dayActive = 365;

          this.openType = false;
          this.openauditResult = false;
          this.getList();
        }
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handleauditResultThreeCommentS() {
      if (this.ids.length < 1) {
        this.$modal.msgError("至少选择一条数据");
        return;
      }
      auditResultThreeCommentS(this.ids).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("智能复核成功");

          this.getList();
        }
      });
    },
    getBiCommentSecondDwdList(row) {
      this.commentFirstId = row.id;

      this.commentContent = row.commentContent;
      this.openInfo = true;
      return;
      let obj = {
        commentFirstId: row.id,
      };
      listBiCommentSecondDwd(obj).then((response) => {
        this.BiCommentSecondDwdList = response.rows;
      });
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      // this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      getCommentTypeByDate(obj).then((response) => {
        this.$modal.closeLoading();

        if (response.code == 200) {
          this.$modal.msgSuccess("批量打标成功");
          this.dayActive = 365;

          this.openauditResult = false;
          this.openType = false;
          this.getList();
        }
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      // this.timeGap.startTime = val[0];
      // this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      // this.timeGap.startTime = value[0];
      // this.timeGap.endTime = value[1];
      // console.log(JSON.stringify(this.timeGap));

      this.queryParams.startDate = value[0];
      this.queryParams.endDate = value[1];

      this.getList();

      this.dayActive = 1;
    },
    //时间控件
    changcommonDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getcommonDay(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));

      // this.queryParams.startDate = this.timeGap.startTime;
      // this.queryParams.endDate = this.timeGap.endTime;

      // this.getList();

      this.dayActive = 1;
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载，请稍候！");
    },

    handlegetCommentTypeByFirstId() {
      if (this.ids.length == 0) {
        this.$modal.msgError("请选择一条数据");
        return;
      }
      this.openLoading();
      getCommentTypeByFirstId(this.ids.join(",")).then((response) => {
        this.$modal.closeLoading();
        this.getList();
      });
    },
    /** 查询评价类型列表 */
    getList() {
      this.loading = true;
      listBiCommentFirstDwd(this.queryParams).then((response) => {
        this.BiCommentFirstDwdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        brand: null,
        channel: null,
        shopName: null,
        shopId: null,
        commentTime: null,
        commentContent: null,
        commentType: null,
        dataYear: null,
        dataMonth: null,
        dataWeek: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评价类型";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiCommentFirstDwd(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改评价类型";
      });
    },
    handleColse() {
      this.openInfo = false;
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiCommentFirstDwd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiCommentFirstDwd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除评价类型编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiCommentFirstDwd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "comment/BiCommentFirstDwd/export",
        {
          ...this.queryParams,
        },
        `BiCommentFirstDwd_${new Date().getTime()}.xlsx`
      );
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传导入文件大小不能超过 100MB!");
      }

      return isLt2M;
    },
    handleRemove(file, fileList) {
      if (!fileList.length) {
        this.hasFile = false;
      }
      this.dataForm.file = null;
    },
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    //确定按钮
    //调用组件upload的submit方法，从而触发httpRequest方法，实现手动上传
    submitUpload() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$refs.uploadImport.submit();
        }
      });
    },
    httpRequest(param) {
      if (this.dataForm.name.length < 2) {
        this.$modal.msgWarning("请选择到渠道");
        return;
      }
      let fd = new FormData();
      fd.append("file", param.file); // 传文件
      fd.append("salesGrade", this.dataForm.name);
      fd.append("origCommentType", this.dataForm.origCommentType);
      // fd.append("brand", this.dataForm.name[0]);
      // fd.append("channel", this.dataForm.name[1]);
      //dataPar.file.raw
      console.log(JSON.stringify(fd));
      this.openLoading();
      axios
        .post(
          process.env.VUE_APP_BASE_API +
            "/comment/BiCommentFirstDwd/importData",
          fd,
          {
            headers: {
              header: { responseType: "blob" },

              Authorization: "Bearer " + getToken(),
              "Content-Type": "multipart/form-data",
            }, //定义内容格式,很重要
            // timeout: 20000,
          }
        )
        .then((response) => {
          this.$modal.closeLoading();
          console.log(response);
          if (response.data.code == 200) {
            this.dialogVisible = false;

            this.$modal.msgSuccess("导入成功");
            this.hasFile = false;
            this.getList();
          } else {
            this.$modal.msgError("导入失败");
          }
        });
    },
    changecascadeList(value) {
      console.log(JSON.stringify(value));
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },

    /** 查询品牌渠道店铺关系列表 */
    getdataSourceList() {
      listAll().then((response) => {
        // let list = [];
        // response.forEach((item) => {
        //   if (item.isTalentLive == "是") {
        //     list.push(item);
        //   }
        // });
        let result = this.transformData(response);
        this.cascadeList = result;
        this.dataForm.name = [
          result[0].label,
          result[0].children[0].label,
          result[0].children[0].children[0].label,
        ];
      });
    },
    //店铺渠道品牌转换

    transformData(data) {
      let result = [];

      data.forEach((item) => {
        let brand = item.brand;
        let channel = item.channel;
        let shopName = item.shopName;

        // 如果brand在结果数组中不存在，则创建一个新的数组
        let brandIndex = result.findIndex(
          (brandObj) => brandObj.label === brand
        );
        if (brandIndex === -1) {
          result.push({
            label: brand,
            value: brand,
            children: [],
          });
          brandIndex = result.length - 1;
        }

        // 如果channel在当前brand的children数组中不存在，则创建一个新的数组
        let channelIndex = result[brandIndex].children.findIndex(
          (channelObj) => channelObj.label === channel
        );
        if (channelIndex === -1) {
          result[brandIndex].children.push({
            label: channel,
            value: channel,
            children: [],
          });
          channelIndex = result[brandIndex].children.length - 1;
        }

        // 如果shopName在当前channel的children数组中不存在，则创建一个新的数组
        let shopIndex = result[brandIndex].children[
          channelIndex
        ].children.findIndex((shopObj) => shopObj.label === shopName);
        if (shopIndex === -1) {
          result[brandIndex].children[channelIndex].children.push({
            label: shopName,
            value: shopName,
            // children: []
          });
        }
      });

      return result;
    },
  },
};
</script>
